<template>
    <h2>修改门店信息</h2>
    <table class="table table-bordered" border="1">
        <tbody>
            <tr>
                <td>店名</td>
                <td>
                    <input type="text" placeholder="请输入店名" v-model="Info.m_name">
                </td>
            </tr>
            <tr>
                <td>营业时间</td>
                <td>
                    <input type="date" v-model="Info.m_kdate">-
                    <input type="date" v-model="Info.m_jdate">
                </td>
            </tr>
            <tr>
                <td>
                    服务范围
                </td>
                <td>
                    <select v-model="Info.t_id">
                        <option value="0">--请选择类型--</option>
                        <option v-for="item in InfoType" :value="item.t_id">{{ item.t_name }}</option>
                    </select>
                </td>
            </tr>
            <tr>
                <td>店主</td>
                <td>
                    <input type="text" placeholder="请输入店主" v-model="Info.m_dianzhu">
                </td>
            </tr>
            <tr>
                <td>联系电话</td>
                <td>
                    <input type="text" placeholder="请输入联系电话" v-model="Info.m_dianhua">
                </td>
            </tr>
            <tr>
                <td>门店介绍</td>
                <td>
                    <textarea  v-model="Info.m_jiesao" placeholder="请输入门店介绍"></textarea>
                </td>
            </tr>
            <tr>
                <td>门店地址</td>
                <td>
                    <input type="text" placeholder="请输入门店地址" v-model="Info.m_dizhi">
                </td>
            </tr>
            <tr>
                <td>状态</td>
                <td>
                    <input type="radio" :value="true"   v-model="Info.m_state">启用
                    <input type="radio" :value="false"  v-model="Info.m_state">禁用
                </td>
            </tr>
            <tr>
                <td>门店Logo</td>
                <td>
                    <img :src="Info.m_img" style="width: 100px;height: 100px;">
        
                </td>
            </tr>
            <tr>
                <td>门店图片</td>
                <td>
                    <input type="file" @change="FileUpLoads">
                </td>
            </tr>
            
            
            <tr>
                <td colspan="2" style="text-align: center;">
                    <input type="button" value="修改" @click="AddGong">
                </td>
        
            </tr>
        </tbody>
    </table>
</template>
<script setup lang="ts">
import {ref,onMounted} from 'vue'
import axios from 'axios';
import { useRouter,useRoute } from 'vue-router';

const router=useRouter()
const route=useRoute()
const InfoType=ref([{
    "t_id": 0,
    "t_name": "string"
  }])
const Info=ref({
  "m_id": route.params.id,
  "m_name": "",
  "m_kdate": "",
  "m_jdate": "",
  "t_id": 0,
  "m_dianzhu": "",
  "m_dianhua": "",
  "m_jiesao": "",
  "m_dizhi": "",
  "m_state": true,
  "m_img": "",
  "m_IsDelete": true
})
onMounted(()=>{
    ShowType()
    fan()
})
const ShowType=()=>{
    axios.get("https://localhost:7258/api/Men/ShowMenType")
    .then(res=>{
        InfoType.value=res.data
    })
}
const fan=()=>{
    axios.get("https://localhost:7258/api/Men/ShowFirst?id="+route.params.id)
    .then(res=>{
        Info.value=res.data
    })
}
const FileUpLoads=(e:any)=>{
    var file=e.target.files[0]
    var fd=new FormData();
    fd.append("image",file)
    axios.post("https://localhost:7258/api/Flies/FileUpload",fd)
    .then(res=>{
    
        if(res.data.comm_Code==-1){
            alert(res.data.comm_Msg)
        }else if(res.data.comm_Code==-2){
            alert(res.data.comm_Msg)
        }else{
            Info.value.m_img=res.data.comm_Path 
        }
       
    })
}
const AddGong=()=>{
    if(Info.value.m_name==""){
        alert("门店名称不能为空")
        return
    }
    if(Info.value.m_dianzhu==""){
        alert("店主不能为空")
        return
    }
    if(Info.value.m_dianhua==""){
        alert("联系电话不能为空")
        return
    }
   
   if(Info.value.m_jiesao==""){
    alert("门店介绍不能为空")
    return
   }
   if(Info.value.m_dizhi==""){
        alert("地址不能为空")
        return
    }
   
    axios.put("https://localhost:7258/api/Men/UpMen",Info.value)
    .then(res=>{
        if(res.data>0){
            alert("门店信息修改成功")
            router.push("/ShowMen")            
        }
    })
}
</script>